package controllers.entorno;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Sequencias {

	public static final String CLIENTE_SQ = "CLIENTE_SQ";

	public static final String PERSONA_SQ = "PERSONA_SQ";

	public static final String REGION_SQ = "REGION_SQ";

	public static final String SUCURSAL_SQ = "SUCURSAL_SQ";

	public static final String EMPLEADO_SQ = "EMPLEADO_SQ";

	public static final String PROVEEDOR_SQ = "PROVEEDOR_SQ";

	public static final String VENTA_SQ = "VENTA_SQ";

	public static final String PEDIDO_SQ = "PEDIDO_SQ";

	public static final String DETALLE_PEDIDO_SQ = "DETALLE_PEDIDO_SQ";

	public static final String FACTURA_SQ = "FACTURA_SQ";

	public static final String DETALLE_FACTURA_SQ = "DETALLE_FACTURA_SQ";

	public static final String MARCA_SQ = "MARCA_SQ";

	public static final String MERCADERIA_SQ = "MERCADERIA_SQ";

	public static final String TIPO_GASTO_SQ = "TIPO_GASTO_SQ";

	public static final String GASTO_SQ = "GASTO_SQ";

	private static Connection getConexion() throws Exception {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		return DriverManager.getConnection(
				"jdbc:oracle:thin:@10.45.3.61:1521:xe", "frodriguez",
				"root");
	}

	public static int getSiguiente(String nombreSequencia)
			throws Exception {
		int id;
		Connection conn = getConexion();
		try {
			Statement st = conn.createStatement();
			try {
				ResultSet rs = st.executeQuery("SELECT " + nombreSequencia
						+ ".nextval FROM dual");
				try {
					rs.next();
					id = rs.getInt(1);
				} finally {
					rs.close();
				}
			} finally {
				st.close();
			}
		} finally {
			conn.close();
		}
		return id;
	}
}
